import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue2'
import { fileURLToPath, URL } from 'node:url'
import postcssPresetEnv from 'postcss-preset-env'
import postcssNesting from 'postcss-nesting'
import VueComponents from 'unplugin-vue-components/vite'
import { ElementUiResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'

export default defineConfig({
  plugins: [
    vue(),
    VueComponents({
      resolvers: [ElementUiResolver()],
    }),
    AutoImport({
      resolvers: [
        (name) => {
          if (name === 'ElLoading') {
            return {
              from: 'element-ui',
              name: 'Loading',
              sideEffects: [
                'element-ui/lib/theme-chalk/base.css',
                'element-ui/lib/theme-chalk/loading.css',
              ],
            }
          }
        },
      ],
      eslintrc: {
        enabled: false,
      },
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  css: {
    postcss: {
      plugins: [postcssPresetEnv, postcssNesting],
    },
  },
})
